﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BGCMS.Models
{
    /// <summary>
    /// A partial model class used for integrating validation and business rule logic
    /// </summary>
    public partial class AppointmentLog
    {
        /// <summary>
        /// Indicates whether the AppointmentLog object has any active RuleViolations
        /// </summary>
        public bool IsValid
        {
            get { return (AppointmentLogGetRuleViolations().Count() == 0); }
        }

        /// <summary>
        /// Causes our validation and business rules to be evaluated.
        /// </summary>
        /// <returns>Returns a sequence of AppointmentLogRuleViolation objects that 
        /// provide more details about any rule errors.</returns>
        public IEnumerable<AppointmentLogRuleViolation> AppointmentLogGetRuleViolations()
        {
            if (String.IsNullOrEmpty(TextBody))
                yield return new AppointmentLogRuleViolation("Hver er textinn", "TextBody"); 
            
            yield break;
        }
    }

    /// <summary>
    /// A helper class that provides more details about a rule violation
    /// </summary>
    public class AppointmentLogRuleViolation
    {

        public string AppointmentLogErrorMessage { get; private set; }
        public string AppointmentLogPropertyName { get; private set; }

        public AppointmentLogRuleViolation(string errorMessage, string propertyName)
        {
            AppointmentLogErrorMessage = errorMessage;
            AppointmentLogPropertyName = propertyName;
        }
    }
}